﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Acme.ConcreteMixDesign.Migrations
{
    /// <inheritdoc />
    public partial class CreateTopicAndInfor : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Answers_Topics_TopicId",
                table: "Answers");

            migrationBuilder.DropForeignKey(
                name: "FK_TopicInformations_Topics_TopicId",
                table: "TopicInformations");

            migrationBuilder.DropIndex(
                name: "IX_TopicInformations_TopicId",
                table: "TopicInformations");

            migrationBuilder.DropIndex(
                name: "IX_Answers_TopicId",
                table: "Answers");

            migrationBuilder.DropColumn(
                name: "TopicId",
                table: "TopicInformations");

            migrationBuilder.CreateTable(
                name: "TopicAndInfors",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    Topid = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    InforId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    CreatorId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    LastModificationTime = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TopicAndInfors", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "TopicAndInfors");

            migrationBuilder.AddColumn<Guid>(
                name: "TopicId",
                table: "TopicInformations",
                type: "char(36)",
                nullable: true,
                collation: "ascii_general_ci");

            migrationBuilder.CreateIndex(
                name: "IX_TopicInformations_TopicId",
                table: "TopicInformations",
                column: "TopicId");

            migrationBuilder.CreateIndex(
                name: "IX_Answers_TopicId",
                table: "Answers",
                column: "TopicId");

            migrationBuilder.AddForeignKey(
                name: "FK_Answers_Topics_TopicId",
                table: "Answers",
                column: "TopicId",
                principalTable: "Topics",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_TopicInformations_Topics_TopicId",
                table: "TopicInformations",
                column: "TopicId",
                principalTable: "Topics",
                principalColumn: "Id");
        }
    }
}
